#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 5010, INF = 0x3f3f3f3f;
int n, m;
vector<PII> edges[N];
int dist[N];
bool st[N];
int prim()
{
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    int ret = 0;
    for (int i = 1; i <= n; i++)
    {
        // 1. 找最近点

        int t = 0;
        for (int j = 1; j <= n; j++)
            if (!st[j] && dist[j] < dist[t])
                t = j;
        // 判断是否联通

        if (dist[t] == INF) return INF;
        st[t] = true;
        ret += dist[t];
        // 2. 更新距离

            for (auto& p : edges[t])
            {
                int a = p.first, b = p.second;
                // t->a 权值b
                dist[a] = min(dist[a], b);
            }
    }
    return ret;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int x, y, z; cin >> x >> y >> z;
        // 如果有重边，怎么办？

        edges[x].push_back({ y, z });
        edges[y].push_back({ x, z });
    }
    int ret = prim();
    if (ret == INF) cout << "orz" << endl;
    else cout << ret << endl;
    return 0;
}